package com.cheboohui.iqs.taiping.direct.order;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cheboohui.iqs.common.basic.StringUtil;
import com.cheboohui.iqs.spring.entity.CarNews;

/**
 * 车型列表获取
 * 
 * @author xielonghai
 *
 */
public class CarListGet {

	/**
	 * 车型列表获取
	 * 
	 * @param vehicle
	 * @return
	 */
	public static List<CarNews> getCars(JSONArray vehicle) {
		List<CarNews> carList = new ArrayList<CarNews>();
		for (int k = 0; k < vehicle.size(); k++) {
			JSONObject li = vehicle.getJSONObject(k);
			CarNews c = new CarNews();
			c.setAutoModelCode(li.getString("modelCode"));
			c.setAutoModelName(li.getString("carBrand"));
			c.setExhaustMeasure(li.getString("exhaustScale"));
			c.setPurchasePrice(li.getString("purchasePrice"));

			String configModel = li.getString("configModel");
			String[] remark = configModel.split(" ");
			if (remark.length > 1)
				c.setRemark(remark[0] + remark[1]);

			for (String o : remark) {
				if (o.indexOf("款") > 0) {
					String year = o.substring(0, o.indexOf("款"));
					if (StringUtil.formatDeal(year, "^[0-9/-]{4,}$")) {
						c.setFirstSaleDate(year);
						continue;
					}
				}

				if (o.indexOf("座") > 0) {
					String seat = o.substring(0, o.indexOf("座"));
					if (StringUtil.formatDeal(seat, "^[0-9]{1,2}$")) {
						c.setSeats(seat);
						continue;
					}
				}
			}

			c.setOptionDisplay();
			carList.add(c);
		}
		return carList;
	}
}
